<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<HEAD>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<TITLE>选择单位</TITLE>
	<script type="text/javascript" language="JavaScript" src="../script/common.js"></script>
	<script type="text/javascript" language="JavaScript" src="../script/tree.js"></script>
	<script type="text/javascript" language="JavaScript">
	var tree;
	var cardUserId = null;
	var rootAsZero;
	function load(){
		cardUserId = getPara("orgId");
		rootAsZero = getPara("rootAsZero");
		if (!cardUserId){
			showWarning("没有指定单位")
			return;
		}
		var cardUserName = unesc(getPara("orgName"));
		if (cardUserName){
			writeTree({id:cardUserId,name:cardUserName})
		}else
			DWR.call("mgntQueryService.getCardUser",cardUserId,function(res){
				if(res){
					writeTree({id:res.cardUser.id,name:res.companyName})
				}
			});
	}
	
	function writeTree(obj){
		obj.isRoot = true
		tree = new LoadTree(obj.name, null,"javascript:void(0)",null,"../images/tree/root.png","../images/tree/root.png");
		tree.obj = obj
		$("depttree").innerHTML = tree;
	}
	
	function _startLoadXmlTree(sSrc, jsNode) {
		var params = {}
		if (sSrc){
			params.cardUserId = cardUserId;
			params.parentId = sSrc;
		}else{
			params.nullParent = cardUserId;
		}
		DWR.call("ejbQueryService.findData","find_dept",params,function(result){
			_xmlFileLoaded(result,jsNode);
		});
	}
	
	function _createNode(r){
		var obj = {id:r[0],name:r[1],stationLimit:r[2]}
		var node = createTreeNode(false,obj.name,obj.id,"javascript:void(0)");
		node.obj = obj;
		return node;
	}
	
	function onSave(){
        if(!tree.getSelected()){
            showWarning("请选择部门后再点击确定。");
            return;
        }
		var v = tree.getSelected().obj;
		if (rootAsZero){
			if (v.isRoot){
				v.id=0;
			}
        }else{
        	if (v.isRoot){
            	showWarning("请选择部门。");
            	return;
        	}
        }
		dialogBackValue(v);
	}
	</script>
	</HEAD>
<BODY class="body" onload='load()'>
	<div id="depttree" class="treeDiv"></div>
</BODY>
</HTML>
